<%--
  Created by IntelliJ IDEA.
  User: Jie
  Date: 2022/10/08
  Time: 15:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript">
        $(function (){
            $("#btn4").click(function (){
                layer.msg("hello");
            });

            $("#btn3").click(function (){
                var student = {
                    "stuId":5,
                    "stuName":"zhangsan",
                    "address": {
                        "province":"广东",
                        "city":"佛山",
                        "street":"狮山"
                    },
                    "subjectList":[{
                        "subjectName":"ssm",
                        "subjectScore":90
                    },
                        {
                            "subjectName":"javase",
                            "subjectScore":95
                        }],
                    "map": {
                        "key1":"value1",
                        "key2":"value2"
                    }
                };
                //将JSON对象转换为JSON字符串
                var s = JSON.stringify(student);
                $.ajax({
                    "url":"send/compose/object.html",
                    "type":"POST",
                    "data":s,
                    "contentType":"application/json;charset=UTF-8",
                    "dataType":"text",
                    "success":function (response){
                        alert(response);
                    },
                    "error":function (response){
                        alert(response);
                    }
                });
            });

            $("#btn2").click(function () {
                //准备要发送的数据
                var array=[4,12,63]
                //必须先将目标转换成JSON字符串
                var arrayStr = JSON.stringify(array)
                $.ajax({
                    url: "send/array/two.html",
                    type: "POST",
                    dataType: "text",
                    contentType: "application/json;charset=utf-8",  //告诉服务器端当前请求的请求体是JSON格式
                    data: arrayStr,
                    success: function (response) {
                        alert(response);
                    },
                    error: function (response) {
                        alert(response);
                    }

                });
            });

            $("#btn1").click(function (){
                $.ajax({
                    "url": "send/array.html",
                    "type": "post",
                    "data": {
                        "array": [5,8,6]
                    },
                    "dataType": "text",
                    "success": function(response){
                        alert(response);
                    },
                    "error": function(response) {
                        alert("response");
                    }
                })
            });
        });

    </script>
</head>
<body>
    <a href="test/ssm.html">点我进入登录页面</a><br/>
    <button id="btn1">send message</button><br/>
    <button id="btn2">send message2</button><br/>
    <button id="btn3">send composeObject</button><br/>
    <button id="btn4">点我弹窗</button><br/>
</body>
</html>
